package com.quasar.hpatient.dialog;

import android.app.Activity;

import com.quasar.hpatient.R;

import java.util.List;

import lib.quasar.base.dialog.BaseDialog;
import lib.quasar.widget.menu.NavigationView;
import lib.quasar.widget.wheel.WheelView;

/**
 * description: 单选
 * created by kalu on 2018/5/14 15:55
 */
public final class RadioDialog extends BaseDialog {

    /**********************************************************************************************/

    private OnDialogChangeListener listener;

    public RadioDialog(Activity activity) {
        super(activity);
    }

    @Override
    protected int initView() {
        return R.layout.layout_dialog_radio;
    }

    @Override
    protected void initData() {

        final NavigationView menu = findViewById(R.id.layout_dialog_type_menu);
        menu.setOnNavigationChangeListener((isBack, isMenu) -> {
            if (isBack) onBackPressed();
            else if (isMenu) {
                if (null != listener) {
                    WheelView wheel = findViewById(R.id.dialog_radio_wheel);
                    final String curText = wheel.getCurText();
                    listener.onChange(curText);
                }
                cancel();
            }
        });
    }

    public void setTitle(String str) {

        final NavigationView menu = findViewById(R.id.layout_dialog_type_menu);
        if (null == menu) return;
        menu.setTitle(str);
    }

    public void setList(List<String> list) {
        setList(list, 0);
    }

    public void setList(List<String> list, int position) {
        final WheelView wheel = findViewById(R.id.dialog_radio_wheel);
        if (null == wheel) return;
        wheel.setList(list, position);
    }

    public void setLoop(boolean loop) {
        final WheelView wheel = findViewById(R.id.dialog_radio_wheel);
        wheel.setLoop(loop);
    }

    public void setOnMethodChangeListener(OnDialogChangeListener mListener) {
        this.listener = mListener;
    }

    public interface OnDialogChangeListener {
        void onChange(String method);
    }
}
